package com.service;

import java.util.HashMap;
import java.util.List;

import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.entity.Statistics;

@Service

public class StatisticsService extends BaseService<Statistics> {
	@Transactional
	public void saveAndDeleteModelByID(Long id) {
		HashMap<String, Long> map = new HashMap<>();
		map.put("id", id);
		update(" ", null);
		delete("  ", map);
	}

	/**
	 * 可缓存get方法，调用之前判断在“all_stastics”缓存中是否有key为方法参数的缓存</br>
	 * 有则直接返回缓存，否则执行方法</br>
	 * </br>
	 * 如果方法没有参数，则使用默认的key
	 * @param key
	 * @return
	 */
	@Cacheable(value = "all_stastics")
	public List<Statistics> getAll(String key) {
		return getList("select * from `statistics` limit 100;", null);
	}

	@Cacheable(value = "all_stastics")
	public List<Statistics> getAll_Cp(String key) {
		return getList("select * from `statistics` limit 1;", null);
	}

	@CacheEvict(value = "all_stastics")
	public void removeCache() {

	}

}
